<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>object</title>
</head>
<body>
<script>
    /*Object.create()方法在基于Object.defineProperties的基础上还可以将
    * 一个对象作为其原型对象*/
   function Person(name,age){
       this.name =name;
       this.age = age;
   }

   Person.prototype.say = function (){
       console.log(this.name)
   }

   function Child(){

   }

   /*使用create进行继承(基于类式继承)*/
   Child.prototype =Object.create(Person.prototype);
   Child.prototype.constructor =Child;


   let child = new  Child();
   child.name = "ASL";
   child.say();

   console.log("----------------------")

   function Fruit(name){
       this.name =name;
   }

  Fruit.prototype.getFruitName = function (){
      console.log(this.name)
  }

  Fruit.prototype.getName = function (){
      console.log("Fruit")
  }

   function Vegetable(type){
       this.type =type;
   }

   Vegetable.prototype.getVegetableName = function (){
       console.log(this.type)
   }

    Vegetable.prototype.getName = function (){
        console.log("Vegetable")
    }


    function Food(name,type){
        Vegetable.call(this,type);
        Fruit.call(this,name);
   }

   Food.prototype = Object.create(Fruit.prototype);
   /*使用Object.assign()进行组合继承会将food从Fruit原型中继承的属性被覆盖*/
   Object.assign(Food.prototype,Vegetable.prototype);
   Food.prototype.constructor =Food;

   let food =new Food("abc","def")

    food.getFruitName();
    food.getVegetableName();

    food.getName();


</script>
</body>
</html>